package tgc.edu.tgq.demo.web.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.SessionAttributes;

import tgc.edu.tgq.demo.entity.Grade;
import tgc.edu.tgq.demo.entity.Student;
import tgc.edu.tgq.demo.entity.TbClass;
import tgc.edu.tgq.demo.service.GradeService;
import tgc.edu.tgq.demo.service.StudentService;
import tgc.edu.tgq.demo.service.TbClassService;

@Controller
@RequestMapping(value = "/selfGrade")
/* @SessionAttributes(value = {"list","stus"}) */
//--------个人成绩录入------------
public class SelfGradeContorller {
	@Autowired
	private TbClassService tbClassService;
	@Autowired
	private StudentService studentService;
	@Autowired
	private GradeService gradeService;
	//------查找所有班级----------
	@RequestMapping(value = "/manage")
	public void manage(ModelMap modelMap) {
		List<TbClass> tbClasses=tbClassService.findAll();
		modelMap.put("list", tbClasses);
	}
	
	//-----------通过班级id查找该班级学生----------
	@RequestMapping(value = "/getstu")
	public String getStu(Integer bjId,ModelMap modelMap) {
		List<Student> students=studentService.findByTbClassId(bjId);
		modelMap.put("list", students);
		return "selfGrade/getstu";
	}
	//----------通过学生id查找学生成绩---------
	@RequestMapping(value = "/table")
	public void table(Integer stuId,ModelMap modelMap) {
		List<Grade> grades=gradeService.findByStudentId(stuId);
		modelMap.put("list", grades);
	}
	
	//--------保存修改的成绩-------------
	@RequestMapping(value = "/cjChange")
	@ResponseBody
	public void cjChange(Integer id,Integer grade) {
		Grade grade2=gradeService.findById(id);
		grade2.setGrade(grade);
		gradeService.save(grade2);
	}
}
